using System;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;

namespace CMS.Data
{
    public class TrangThaiXuLyDao : AbstractNHibernateDao<TrangThaiXuLy, System.Int32>, ITrangThaiXuLyDao
    {
        #region Create Instance
        private static TrangThaiXuLyDao instance = null;
        public static TrangThaiXuLyDao Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new TrangThaiXuLyDao();
                }
                return instance;
            }
        }
        #endregion     

        public byte GetMaxSTT()
        {
            byte result = 1;
            try
            {
                Object obj = null;
                String strSQL = @"Select Max(o.STT)from TrangThaiXuLy o ";
                obj = NHibernateSessionManager.Instance.GetSession().CreateQuery(strSQL)
                    .UniqueResult();
                if (obj != null)
                {
                    result = Convert.ToByte(obj);
                    result += 1;
                }
                return result;
            }
            catch
            {
                return result;
            }
        }

        public List<TrangThaiXuLy> GetAllHasOrderBy(bool TrangThai)
        {
            try
            {
                String strQuery = @"From TrangThaiXuLy o Where o.TrangThai =:TrangThai Order by o.STT, o.TenTTXL";
                List<TrangThaiXuLy> Result = NHibernateSessionManager.Instance.GetSession().CreateQuery(strQuery)
                        .SetParameter("TrangThai", TrangThai)
                        .List<TrangThaiXuLy>() as List<TrangThaiXuLy>;
                return Result;
            }
            catch
            {
                return new List<TrangThaiXuLy>();
            }
        }
    }
}
